<template>
  <Teleport to="body">
    <div class="lx__dialog-wrap" v-if="show">
      <div class="lx__dialog-modal">
        <div class="lx__dialog-box" :style="{ width }">
          <div class="lx__dialog-header flex flex--b">
            <div class="title-box">{{ title }}</div>
            <span
              class="iconfont icon-error-bold close-icon"
              @click="close"
            ></span>
          </div>
          <div class="lx__dialog-body">
            <slot />
          </div>
          <div class="lx__dialog-footer">
            <slot name="footer" />
          </div>
        </div>
      </div>
    </div>
  </Teleport>
</template>
<script lang="ts" setup>
import { computed, toRefs } from "vue";

const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false,
  },
  title: {
    type: String,
    default: "",
  },
  width: {
    type: String,
    default: "600px",
  },
});
const { title, width } = toRefs(props);
const emit = defineEmits(["update:modelValue"]);
const show = computed({
  set(val) {
    emit("update:modelValue", val);
  },
  get() {
    return props.modelValue;
  },
});
const close = () => {
  show.value = false;
};
</script>
<style lang="scss" scoped>
.lx__dialog-modal {
  width: 100vw;
  height: 100vh;
  z-index: 9998;
  position: fixed;
  left: 0;
  top: 0;
  background-color: rgba($color: #000000, $alpha: 0.7);
  overflow: hidden;
}
.lx__dialog-box {
  z-index: 9999;
  margin: 15vh auto 50px;
  background-color: #fff;
  border-radius: 5px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  position: relative;
}
.lx__dialog-header {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  .close-icon {
    color: #ccc;
    cursor: pointer;
  }
}
.lx__dialog-body {
  padding: 10px 20px;
  max-height: 60vh;
  overflow-y: auto;
}
.lx__dialog-footer {
  width: 100%;
  height: 48px;
  padding: 0 20px;
}
</style>
